<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>书籍详情</title>
    <script type="text/javascript" src="../js/First_Page.js"></script>
    <link rel="stylesheet" href="../style/First_Page.css"/>
    <link rel="stylesheet" href="../style/Goods_Information.css"/>
    <script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.4.1.js"></script>
    <script type="text/javascript" src="../js/Goods_Information.js"></script>
    <script type="text/javascript">
        window.onload=function () {
            var a ="${sessionScope.login}";
            if(a=="1"){
                document.getElementById("login").style.display="none";
                document.getElementById("avatar").style.display="inline";
                document.getElementById("buy_car").style.display="inline";
                document.getElementById("car_image").style.display="inline";
                document.getElementById("exit").style.display="inline";
            }
            else{
                document.getElementById("login").style.display="inline";
                document.getElementById("avatar").style.display="none";
                document.getElementById("buy_car").style.display="none";
                document.getElementById("car_image").style.display="none";
                document.getElementById("exit").style.display="none";
            }
        }
    </script>
</head>
<body>
<div id="main_head_box">
    <div class="head_box">
        <div id="head_wrap">
            <div id="head_right">
                <div id="head_landing">
                    <a id="login" class="head_nav_a" href="http://localhost:8080/Login.html" style="display: inline;">登陆/注册</a>
                    <a href="http://localhost:8080/Self_Information.jsp"><img src="${sessionScope.user.avatar}" id="avatar" style="display: none;height:30px;width:30px;border-radius: 45px;margin-right:50px;margin-top: 5px;"></a>
                    <a id="exit" style="display: none;float:right;margin-left:15px;" href="First_Page.jsp" onclick="login2exit()">注销</a>
                    <img src="http://localhost:8080/image/buy_car.jpg" style="display:none;height:30px;width:30px;border-radius: 90px" id="car_image">
                    <a id="buy_car" class="head_nav_a" style="display: block;float:right;margin-left:5px;" href="http://localhost:8080/Buy_Car.jsp">购物车</a>
                </div>
            </div>
        </div>
    </div>
    <div id="menu_wrap">
        <p id="menu_logo">读了么 <i>DuLeMe.com</i></p>
        <div id="find_wrap">
            <div id="find_bar">
                <input type="text" id="find_input">
            </div>
            <div id="find_but" onclick="search_method()"><a>GO</a></div>
        </div>
    </div>
</div>
<div id="Goods_Main">
    <div class="img_div">
        <img src=${requestScope.book.cover} style="height:422px;width:350px;margin-left:150px;margin-top:50px">
    </div>
    <div class="information_div">
        <p style="font-size:22px;"><b>${requestScope.book.bookName}</b></p>
        <div class="book_price">
            <p id="book_price_p1">价格</p>
            <p id="book_price_p2"><b>￥${requestScope.book.price}</b></p>
        </div>
        <div class="transport_price_div">
            <p id="transport_price_p1">运费</p>
            <p id="transport_price_p2"><b>包邮</b></p>
        </div>
        <div class="book_count_div">
            <p id="book_count_p1">数量</p>
            <input type="text" value="1" id="count_input">
            <div class="price_button_div">
                <input type="button" id="count_up" value="⌃" onclick="count_up()">
                <input type="button" id="count_down" value="⌃" onclick="count_down()">
            </div>
        </div>
        <div class="price_pay_div">
            <input type="button" id="buy" value="立即购买" onclick="buy_cart()" >
            <input type="button" id="putin_cart" value="放入购物车" onclick="putIntoCart()">
        </div>
        <div class="assure_div">
            <p id="assure_p1">服务承诺</p>
            <p id="assure_p2">正品保证  &nbsp;&nbsp;极速退款  &nbsp;&nbsp;赠运费险 &nbsp;&nbsp;七天无理由退换</p>
        </div>
        <div class="bookshop_div">
            <p id="bookshop_p1">书籍简介</p>
            <p id="bookshop_p2">${requestScope.book.synopsis}</p>
        </div>
    </div>
</div>
<span class="title_span" style="float:right;margin-right: 100px;"><a href="http://localhost:8080/Shop_Main.jsp?shopId=${requestScope.book.shopId}&method=shop">点击进入商店>></a></span>
<div id="foot_box" style="margin-left:150px;">
    <div id="foot_wrap">
        <div class="foot_top">
            <ul>
                <li><a href="Self_Information.jsp">个人信息设置</a></li>
                <li class="font_top_i">|</li>
                <li><a href="First_Page.jsp">返回首页</a></li>
                <li class="font_top_i">|</li>
                <li>用户购物指南</li>
                <li class="font_top_i">|</li>
                <li><a href="user_Agreement.html">用户协议须知</a></li>
            </ul>
        </div>
        <div class="foot_bottom">
            <span> <a href="">返回顶部</a></span>
        </div>
    </div>
</div>
</body>
<script>
    function putIntoCart() {
        var login = "${sessionScope.login}";
        if (login==1){
            if (buy()) {
                var count = $("#count_input").val();
                var bookID = "${requestScope.book.bookId}";
                $.post("/data/cart","bookID="+bookID+"&&count="+count,function (data,status) {
                    if(data.result==1){
                        alert("添加成功");
                        window.location.href="http://localhost:8080/First_Page.jsp";
                    }
                    else {
                        alert(data.result);
                    }
                },"json");
            }
        }else {
            alert("请登陆后再购买");
        }
    }
    
    function buy_cart() {
        alert("功能尚未开发，敬请期待");
    }
</script>
</html>